package homework.test1
//找到所有的水仙花数:水仙花数是这样的一个三位数：这个数等于每一位上的数的立方和,比如153
import scala.collection.mutable.ArrayBuffer
object NarcissisticNumber {

    def findNarcissisticNumbers(): ArrayBuffer[Int] = {
      val array = ArrayBuffer[Int]()
      for (num <- 100 to 999) {
        val x = num % 10
        val y = (num / 10) % 10
        val z = num / 100
        val sumOfCubes = x * x * x + y * y * y + z * z * z
        if (num == sumOfCubes) {
          array += num
        }
      }
      array
    }

    def main(args: Array[String]): Unit = {
      val marcissisticNumber = findNarcissisticNumbers()
      println("所有的水仙花数：")
      marcissisticNumber.foreach(println)
    }

}